package com.twu.biblioteca;

import java.util.ArrayList;

public class Book {
    private static final String BOOK_1 = "Book_one";
    private static final String BOOK_2 = "Book_two";
    private static final String BOOK_3 = "Book_three";
    private static final String BOOK_4 = "Book_four";
    private static final String INPUT_PROMPT = "Enter the reserved book No. : ";
    private static final String ERROR_PROMPT = "Sorry we don't have that book yet.";
    private static final String SUCCESS_PROMPT = "Thank You! Enjoy the book.";


    private ArrayList<String> _booksList = new ArrayList<String>();

    public Book(){
        _booksList.add(BOOK_1);
        _booksList.add(BOOK_2);
        _booksList.add(BOOK_3);
        _booksList.add(BOOK_4);
    }

    public ArrayList<String> getItems(){
        return _booksList;
    }

    public String getInputPrompt(){
        return INPUT_PROMPT;
    }

    public String getErrorPrompt(){
        return ERROR_PROMPT;
    }

    public String getSuccessPrompt(){
        return SUCCESS_PROMPT;
    }



    public boolean selectedOptionValidation(String selectedOption) {
        if(selectedOption == null){
            return false;
        }
        else{
            int optionNum = Integer.parseInt(selectedOption);
            return optionNum>=1 && optionNum<= getItems().size();
        }
    }

    public void inputOption(User user) {
        boolean isValid = false;
        String selectedOption;
        while(!isValid){
            selectedOption = user.getUserInput(getInputPrompt());
            isValid = selectedOptionValidation(selectedOption);
            if(isValid) break;
            System.out.println(getErrorPrompt());
        }
        System.out.println(getSuccessPrompt());

    }

}
